import { Consts } from "../Data/Consts";
import { GameData } from "../Data/GameData";
import GamePanel from "../UI/GamePanel";
// import GameManager from "./GameManager";

const { ccclass, property } = cc._decorator;

@ccclass
export default class TimerManager extends cc.Component {
    public static Instance: TimerManager;

    // 游戏提示
    // timer_GameTip: number = 0;
    // timerCount_GameTip: number = 1;
    // timerPlay_GameTip: boolean = false;

    timer_speed: number = 0;
    timerCount_speed: number = 0.16;
    timerPlay_speed: boolean = false;

    timer_发动进攻: number = 0;
    timerCount_发动进攻: number = 800000000000 // 8; // 10;
    timerPlay_发动进攻: boolean = false;

    onLoad() {
        TimerManager.Instance = this;
        this.AddListener();
        // this.Play_all();

        this.timerPlay_发动进攻 = true;
    }

    AddListener() {
        cc.systemEvent.on(Consts.EventType.TOUCH_SCREEN, () => {
            // this.Reset_timer_GameTip();
        });
    }

    update(deltaTime: number) {
        if (this.timerPlay_发动进攻) {
            this.timer_发动进攻 += deltaTime;

            if (this.timer_发动进攻 >= this.timerCount_发动进攻) {
                this.timer_发动进攻 = 0;

                this.timerPlay_发动进攻 = false;
                GameData.下落是否暂停 = true;
            }
        }

        if (this.timerPlay_speed) {
            this.timer_speed += deltaTime;
            if (this.timer_speed >= this.timerCount_speed) {
                this.Stop_timer_speed();
                // console.log(GameManager.Instance.speed);
            }
        }
        // if (this.timerPlay_GameTip) {655596
        //     if (this.timer_GameTip >= this.timerCount_GameTip) {
        //         this.Reset_timer_GameTip();
        //         this.Handler_timer_GameTip();
        //     }
        // }
    }

    Start_timer_speed() {
        this.timerPlay_speed = true;
        this.timer_speed = 0;
    }

    Stop_timer_speed() {
        this.timerPlay_speed = false;
    }

    // Play_all() {
    //     this.Play_timer_GameTip();
    // }

    // Stop_all() {
    //     this.Stop_timer_GameTip();
    // }

    // Reset_timer_GameTip() {
    //     this.timer_GameTip = 0;
    // }

    Handler_timer_GameTip() {
        cc.systemEvent.emit(Consts.EventType.GAMETIP);
    }

    static async AwaitTime(_duration) {
        await new Promise(res => TimerManager.Instance.scheduleOnce(res, _duration));
    }
}

/**调试 */
window["TimerManager"] = TimerManager;
